package com.hd.view.action;

import java.util.List;

import com.hd.common.Common;
import com.hd.common.DataPage;
import com.hd.persistence.model.AssignRecord;
import com.hd.persistence.model.Customer;
import com.hd.persistence.model.Machine;
import com.hd.persistence.model.Person;

/**
 * 调派单Action
 * @author jiaoyang
 *
 */

public class AssignRecordAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private AssignRecord assignRecord;
	/*客户名*/
	private List<Customer> customers;
	/*机型*/
	private List<Machine> machines;
	/*作业人员*/
	private List<Person> maintenanceMen;
	/*作业日*/
	private String workday;
	/*要求到达时间*/
	private String reachTime;
	/*要求完成时间*/
	private String completeTime;
	/*查询出的调派单*/
	private DataPage<AssignRecord> assignRecords;
	/** 
	 * 新增调派单
	 */
	public String addNewAssignRecord() throws Exception{
		/*列出所有客户*/
		customers = purchaseManager.listCustomers();
		/*列出所有维修员*/
		maintenanceMen = memberManager.listPerson(2,false);
		/*列出所有机器*/
		machines = memberManager.listMachine();
		return SUCCESS;
	}
	
	/**
	 * 保存调派单
	 */
	public String saveAssignRecord() throws Exception{
		assignRecord.setWorkday(Common.String2Date(workday));
		assignRecord.setReachTime(Common.String2long(reachTime));
		assignRecord.setCompleteTime(Common.String2long(completeTime));
		assignRecord.setCreateTimestamp(System.currentTimeMillis());
		
		repairManager.saveAssignRecord(assignRecord);
		
		statusTemp = true;
		return SUCCESS;
	}
	
	/**查询调派单
	 * @return
	 * @throws Exception
	 */
	public String listAssignRecords() throws Exception{
		/*列出所有客户*/
		customers = purchaseManager.listCustomers();
		/*列出所有机器*/
		machines = memberManager.listMachine();
		/*列出所有维修员*/
		maintenanceMen = memberManager.listPerson(2,false);
		
		if(assignRecord == null){
			assignRecord = new AssignRecord();
		}
		assignRecords = repairManager.pageQueryAssignRecords(assignRecord.getUnitName(), assignRecord.getUnitForShort(), assignRecord.getMachineModel(), assignRecord.getRepairman(), Common.String2Date(workday), getCurrentPage(), pageSize);
		setTotalPage(assignRecords.getTotalPageCount());
		return SUCCESS;
	}

	
/*===================get,set方法===========================================================*/	
	public AssignRecord getAssignRecord() {
		return assignRecord;
	}
	
	public void setAssignRecord(AssignRecord assignRecord) {
		this.assignRecord = assignRecord;
	}

	public List<Customer> getCustomers() {
		return customers;
	}

	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	public List<Machine> getMachines() {
		return machines;
	}

	public void setMachines(List<Machine> machines) {
		this.machines = machines;
	}

	public List<Person> getMaintenanceMen() {
		return maintenanceMen;
	}

	public void setMaintenanceMen(List<Person> maintenanceMen) {
		this.maintenanceMen = maintenanceMen;
	}

	public String getWorkday() {
		return workday;
	}

	public void setWorkday(String workday) {
		this.workday = workday;
	}

	public String getReachTime() {
		return reachTime;
	}

	public void setReachTime(String reachTime) {
		this.reachTime = reachTime;
	}

	public String getCompleteTime() {
		return completeTime;
	}

	public void setCompleteTime(String completeTime) {
		this.completeTime = completeTime;
	}

	public DataPage<AssignRecord> getAssignRecords() {
		return assignRecords;
	}

	public void setAssignRecords(DataPage<AssignRecord> assignRecords) {
		this.assignRecords = assignRecords;
	}
	
}
